package com.yumiusik.common.domain;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;

import pe.com.trestperu.common.util.Constants;

@Entity
@Table(name = "USER_PLAYER")
public class PlayerUser implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "CODE", nullable = false)
	private Long code;

	@Basic(optional = false)
    @Column(name = "EMAIL", nullable = false, length = 150)
	private String email;

	@Basic(optional = true)
    @Column(name = "PASS", nullable = true, length = 150)
	private String pass;

	@Basic(optional = true)
    @Column(name = "FACEBOOK_ID", nullable = true, length = 150)
	private String facebookID;

	@Basic(optional = true)
    @Column(name = "FIRST_NAME", nullable = true, length = 500)
	private String firstName;

	@Basic(optional = true)
    @Column(name = "LAST_NAME", nullable = true, length = 500)
	private String lastName;

	@Basic(optional = false)
    @Column(name = "USER_TYPE", nullable = false, length = 1)
	private String userType;// F = FREE / P = PAYED

	@Basic(optional = true)
    @Column(name = "BIRTH_DATE", nullable = true)
	private Date birthDate;

	public Long getCode() {
		return code;
	}

	public void setCode(Long code) {
		this.code = code;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}

	public String getFacebookID() {
		return facebookID;
	}

	public void setFacebookID(String facebookID) {
		this.facebookID = facebookID;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}

	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	public String getBirthDateDisplay() {
		String fechaOut = StringUtils.EMPTY;
		if(birthDate != null){
			fechaOut = (new SimpleDateFormat(Constants.DATE_FORMAT)).format(birthDate);
		}
		return fechaOut;
	}

	public void setBirthDateDisplay(String birthDate) {
		try {
			if(StringUtils.isNotEmpty(birthDate))
				this.birthDate = DateUtils.parseDate(birthDate, new String[]{Constants.DATE_FORMAT});
			else
				this.birthDate = null;
		} catch (ParseException e) {
			this.birthDate = null;
		}
	}
}